document.addEventListener("DOMContentLoaded", function () {
  layui.use(["layer", "form", "laydate", "element"], function () {
    var layer = layui.layer,
      form = layui.form,
      laydate = layui.laydate,
      element = layui.element,
      indexItemm = [],
      indexItem = [],
      flagg = "",
      selectedDataList = [];
    var urlData = "";
    window.firstClick = true;
    function formatRepeaNum(n) {
      n = n.toString();
      return n[1] ? n : `0${n}`;
    }
    calendarEl = document.getElementById("calendar");
    var calendar = new FullCalendar.Calendar(calendarEl, {
      height: "100%",
      buttonText: { today: false },
      headerToolbar: {
        left: "title",
        center: "today prev,next",
        right: "",
      },
      firstDay: 1,
      theme: false, //如果设置为true，则需要加载jquery ui相关css和js文件,默认值为false
      isRTL: false, //设置为ture时则日历从右往左显示
      navLinks: false,
      displayEventEnd: false,
      // weekNumberCalculation: "ISO",
      locale: "zh-cn",
      eventTimeFormat: {
        hour: "numeric",
        minute: "2-digit",
        meridiem: false,
      },
      omitZeroMinute: false,
      eventColor: "#334d80",
      events: function (args, callback, a, b) {
        let events = [];
        // let loadIndex = layer.load(1, { time: 10 * 1000 });
        let timer = setTimeout(() => {
          var date = calendar.getDate(); // 可以获得操作后的日期
          year = new Date(date).getFullYear();
          month = new Date(date).getMonth() + 1;
          urlData = year + "-" + formatRepeaNum(month);
          ajax(urlData);
          clearTimeout(timer);
        }, 0);
        function ajax(obj) {
          console.log("1-" + obj);
          $.ajax({
            type: "get",
            async: true, //异步执行
            url: base_url + "/meeting/list/month",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            dataType: "json",
            data: { month: obj },
            success: function (res) {
              // layer.closeAll(); // 关闭加载弹窗！！！
              if ((res.code = "200")) {
                var data = res.data.data;
                console.log("res.data.data: ", res.data.data);
                data &&
                  data.length &&
                  data.forEach((event) => {
                    // 往events数组中放入fullcalender展示数据所需要的数据格式
                    events.push({
                      id: event.id, // 日程id
                      title: getTitle(event),
                      start: event.startTime, // 日程开始时间
                      end: event.endTime, // 日程结束时间
                    });
                  });

                callback(events);
              }
            },
          });
        }
      },

      eventContent: function (arg) {
        let italicEl = document.createElement("div");
        italicEl.setAttribute("class", "dayItemBox");
        // str.replace(/\s+|<[^>]+>/g,"-"); // '去除标签'
        let Html = arg.event._def.title;
        let strHtml = Html.replace(/\s+|<[^>]+>/g, "").replace(/&nbsp;/g, "-");
        // let newStrHtml = Html.replace(/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/g);
        italicEl.innerHTML = arg.event._def.title;
        italicEl.title = strHtml;
        var arrayOfDomNodes = [italicEl];
        return { domNodes: arrayOfDomNodes };
      },
      //点击日历中某个事情时候触发
      eventClick: function (arg, jsEvent, view) {
        openEditLayer(arg);
      },
    });
    function getTitle(event) {
      var html = "";
      if (event.type == "线上会议") {
        html = '<div class="offlineMeetingDay classMeetingDay">线上会议</div>';
      } else if (event.type == "线下内部会议") {
        html =
          '<div class="onlineConferenceSty classMeetingDay">' +
          event.type +
          "</div>";
      } else if (event.type == "线下外部会议") {
        html =
          '<div class="offLineOutMeetings classMeetingDay">' +
          event.type +
          "</div>";
      }
      var htmlNewIcon = "";
      if (event.meetingStatus == 1) {
        htmlNewIcon =
          '<img src="../../layuiadmin/images/newIcon.png" class="meetNewIconImg"/>';
      } else if (event.meetingStatus == 2) {
        htmlNewIcon = "";
      }
      var meetingStarttime = event.startTime.split(" ")[1].substring(0, 5);
      var content =
        '<li data-id="' +
        event.userMeetingId +
        '">' +
        htmlNewIcon +
        "<div class='meetingEventItem'><span>" +
        meetingStarttime +
        "</span> &nbsp;" +
        '<span class="headlineMarker" >' +
        event.meetingHeadline +
        "</span></div>" +
        '<span class="marker">' +
        "</span>" +
        html +
        "</li>";
      return content;
    }

    calendar.render();
    function renderData() {
      $(".changeTimeBar ul").html();
      var html = "";
      var timePoint = [
        "08:00",
        "08:30",
        "09:00",
        "09:30",
        "10:00",
        "10:30",
        "11:00",
        "11:30",
        "12:00",
        "12:30",
        "13:00",
        "13:30",
        "14:00",
        "14:30",
        "15:00",
        "15:30",
        "16:00",
        "16:30",
        "17:00",
        "17:30",
        "18:00",
      ];
      for (var i = 0; i < timePoint.length; i++) {
        html += '<button  type="button">' + timePoint[i] + "</button>";
      }
      $(".changeTimeBar ul").html(html);
      // let indexItemm = [];
      let indexDataa = [];
      let timeItemm = [];
      $(".changeTimeBar ul button").on("click", function () {
        let valueText = $(this).text();
        let indexId = $(this).index();
        indexItemm.push(valueText);
        indexDataa.push(indexId);

        if (indexItemm.length == 1) {
          $(this).css("background-color", "#e79e4c");
        } else if (indexItemm.length == 2) {
          indexDataa.sort((a, b) => {
            return a - b;
          });
          var arr = timePoint.slice(indexDataa[0] + 1, indexDataa[1]);
          var ffd = arr.map((item, index) => {
            return timeItemm.includes(item);
          });
          if (ffd.indexOf(true) > -1) {
            var startIndex = indexDataa[0];
            var endIndex = indexDataa[1];
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            $(".changeTimeBar ul button")
              .eq(endIndex)
              .css("background-color", "rgb(192, 206, 235)");
            indexItem.length = 0;
            indexDataa.length = 0;
            indexItem.push(valueText);
            indexDataa.push(indexId);
            $(this).css("background-color", "#e79e4c");
          } else {
            var startIndex = indexDataa[0];
            var endIndex = indexDataa[1];
            getIndex(startIndex, endIndex + 1);
          }
        } else {
          var startIndex = indexDataa[0];
          var endIndex = indexDataa[1];
          clearIndex(startIndex, endIndex + 1);

          indexItemm.length = 0;
          indexDataa.length = 0;
          indexItemm.push(valueText);
          indexDataa.push(indexId);
          $(this).css("background-color", "#e79e4c");
        }

        function getIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "#e79e4c");
            startIndex++;
            getIndex(startIndex, endIndex);
          }
        }
        function clearIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            startIndex++;
            clearIndex(startIndex, endIndex);
          }
        }
      });
    }
    function renderDataW(roomKey) {
      $(".changeTimeBarW ul").html();
      var html = "";
      let timeItem = [];

      var timePoint = [
        "08:00",
        "08:30",
        "09:00",
        "09:30",
        "10:00",
        "10:30",
        "11:00",
        "11:30",
        "12:00",
        "12:30",
        "13:00",
        "13:30",
        "14:00",
        "14:30",
        "15:00",
        "15:30",
        "16:00",
        "16:30",
        "17:00",
        "17:30",
        "18:00",
      ];

      var html = "";
      if (roomKey != "") {
        (disabled = false), (flgVal = true);
        let times = result[roomKey];

        for (var i = 0; i < timePoint.length; i++) {
          let flag = false;
          for (var j = 0; j < times.length; j++) {
            let time = times[j];
            flag =
              timePoint[i] >= time["startTime"] &&
              timePoint[i] <= time["endTime"];
            if (flag) {
              selectedDataList.push(timePoint[i]);
              break;
            }
          }
          if (flag) {
            timeItem.push(timePoint[i]);
            html +=
              '<button  type="button" class="active" disabled=' +
              !disabled +
              ">" +
              timePoint[i] +
              "</button>";
          } else {
            html += '<button type="button" >' + timePoint[i] + "</button>";
          }
        }
      } else {
        for (var i = 0; i < timePoint.length; i++) {
          html += '<button type="button" >' + timePoint[i] + "</button>";
        }
      }
      $(".changeTimeBarW ul").html(html);
      // let indexItemm = [];
      let indexDataa = [];
      let timeItemm = [];
      $(".changeTimeBarW ul button").on("click", function () {
        let valueText = $(this).text();
        let indexId = $(this).index();
        indexItemm.push(valueText);
        indexDataa.push(indexId);

        if (indexItemm.length == 1) {
          $(this).css("background-color", "#e79e4c");
        } else if (indexItemm.length == 2) {
          indexDataa.sort((a, b) => {
            return a - b;
          });
          var arr = timePoint.slice(indexDataa[0] + 1, indexDataa[1]);
          var ffd = arr.map((item, index) => {
            return timeItemm.includes(item);
          });
          if (ffd.indexOf(true) > -1) {
            var startIndex = indexDataa[0];
            var endIndex = indexDataa[1];
            $(".changeTimeBarW ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            $(".changeTimeBarW ul button")
              .eq(endIndex)
              .css("background-color", "rgb(192, 206, 235)");
            indexItem.length = 0;
            indexDataa.length = 0;
            indexItem.push(valueText);
            indexDataa.push(indexId);
            $(this).css("background-color", "#e79e4c");
          } else {
            var startIndex = indexDataa[0];
            var endIndex = indexDataa[1];
            getIndex(startIndex, endIndex + 1);
          }
        } else {
          var startIndex = indexDataa[0];
          var endIndex = indexDataa[1];
          clearIndex(startIndex, endIndex + 1);

          indexItemm.length = 0;
          indexDataa.length = 0;
          indexItemm.push(valueText);
          indexDataa.push(indexId);
          $(this).css("background-color", "#e79e4c");
        }

        function getIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBarW ul button")
              .eq(startIndex)
              .css("background-color", "#e79e4c");
            startIndex++;
            getIndex(startIndex, endIndex);
          }
        }
        function clearIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBarW ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            startIndex++;
            clearIndex(startIndex, endIndex);
          }
        }
      });
    }
    function renderDatePick(roomKey) {
      $(".changeTimeBar ul").html();
      let times = result[roomKey];
      let timeItem = [];
      var timePoint = [
        "08:00",
        "08:30",
        "09:00",
        "09:30",
        "10:00",
        "10:30",
        "11:00",
        "11:30",
        "12:00",
        "12:30",
        "13:00",
        "13:30",
        "14:00",
        "14:30",
        "15:00",
        "15:30",
        "16:00",
        "16:30",
        "17:00",
        "17:30",
        "18:00",
      ];
      var html = "",
        disabled = false,
        flgVal = true;

      for (var i = 0; i < timePoint.length; i++) {
        let flag = false;
        for (var j = 0; j < times.length; j++) {
          let time = times[j];
          flag =
            timePoint[i] >= time["startTime"] &&
            timePoint[i] <= time["endTime"];
          if (flag) {
            selectedDataList.push(timePoint[i]);
            break;
          }
        }
        if (flag) {
          timeItem.push(timePoint[i]);
          html +=
            '<button  type="button" class="active" disabled=' +
            !disabled +
            ">" +
            timePoint[i] +
            "</button>";
        } else {
          html += '<button type="button" >' + timePoint[i] + "</button>";
        }
      }
      $(".changeTimeBar ul").html(html);
      $(".changeAddBar").html(roomKey);
      let chooseAfterValue = [];
      // let indexItem = [];
      let indexData = [];
      $(".changeTimeBar ul button").on("click", function () {
        let valueText = $(this).text();
        let indexId = $(this).index();
        indexItem.push(valueText);
        indexData.push(indexId);

        if (indexItem.length == 1) {
          $(this).css("background-color", "#e79e4c");
        } else if (indexItem.length == 2) {
          indexData.sort((a, b) => {
            return a - b;
          });

          var arr = timePoint.slice(indexData[0] + 1, indexData[1]);
          var ffd = arr.map((item, index) => {
            return timeItem.includes(item);
          });
          if (ffd.indexOf(true) > -1) {
            var startIndex = indexData[0];
            var endIndex = indexData[1];
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            $(".changeTimeBar ul button")
              .eq(endIndex)
              .css("background-color", "rgb(192, 206, 235)");
            indexItem.length = 0;
            indexData.length = 0;
            indexItem.push(valueText);
            indexData.push(indexId);
            $(this).css("background-color", "#e79e4c");
          } else {
            var startIndex = indexData[0];
            var endIndex = indexData[1];
            getIndex(startIndex, endIndex + 1);
          }
        } else {
          var startIndex = indexData[0];
          var endIndex = indexData[1];
          clearIndex(startIndex, endIndex + 1);

          indexItem.length = 0;
          indexData.length = 0;
          indexItem.push(valueText);
          indexData.push(indexId);
          $(this).css("background-color", "#e79e4c");
        }

        function getIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "#e79e4c");
            startIndex++;
            getIndex(startIndex, endIndex);
          }
        }
        function clearIndex(startIndex, endIndex) {
          if (startIndex < endIndex) {
            $(".changeTimeBar ul button")
              .eq(startIndex)
              .css("background-color", "rgb(192, 206, 235)");
            startIndex++;
            clearIndex(startIndex, endIndex);
          }
        }
      });
      // $(".changeTimeAdd .closeBtn").on("click", function () {
      //   $(".changeTimeAdd").hide();
      //   var chooseAfterValueNew = indexItem.sort((a, b) => {
      //     return a > b ? 1 : -1;
      //     // return  a-b
      //   });
      //   $("#changeDateS").val(chooseAfterValueNew[0]);
      //   $("#changeDateE").val(chooseAfterValueNew[1]);
      //   $("#changeDateA").val($("#changeAddress").text().trim());
      // });
    }
    function initDateCtrl() {
      //日期时间选择器
      laydate.render({
        elem: "#meetingDate", //指定元素
        min: 0,
        ready: function (value) {
          disabled_date(value, $("#appointmentDate").val());
        },
        change: function (value, date) {
          disabled_date(date, $("#appointmentDate").val());
        },
        done: function (value, date) {
          if (flagg == 1) {
            changeTimeForm = layer.open({
              title: "",
              type: 1,
              fix: false,
              skin: "layui-layer-rim",
              // 加上边框
              area: ["43%", "37%"],
              // 宽高
              content: $("#changeTimeForm").html(),
              success: function (layero, index) {
                renderData();
              },
              cancel: function (index, layero) {
                var chooseAfterValueNew = indexItemm.sort((a, b) => {
                  return a > b ? 1 : -1;
                });
                if (chooseAfterValueNew.length == 0) {
                  $("#meetingTime").html("");
                } else {
                  $("#meetingTime").html(
                    chooseAfterValueNew[0] + "-" + chooseAfterValueNew[1]
                  );
                  $("#type").val(1);
                  layer.close(index);
                  return false;
                }
              },
            });
          } else if (flagg == 2) {
            $("#meetingTime").html();
            layer.open({
              title: "",
              type: 1,
              fix: false,
              skin: "outChangeTimeForm",
              // 加上边框
              area: ["45%", "55%"],
              // 宽高
              content: $("#outChangeTimeForm").html(),
              success: function (layero, index) {
                element.tabChange("onChangeAddress", 0);
                if (onChangeAddressIndex == 0) {
                  $.ajax({
                    type: "GET",
                    async: true, //异步执行
                    url: base_url + "/meeting/offlineMeetings/" + value,
                    headers: {
                      Accept: "application/json; charset=utf-8",
                      Authorization: layui.sessionData("userToken").key,
                    },
                    success: function (data) {
                      if (data.type == "success") {
                        $("#changeAddress").empty();
                        result = data.data;
                        $.each(data.data, function (index, item) {
                          $("#changeAddress").append(new Option(index));
                        });
                        form.on(
                          "select(changeAddressFilter)",
                          renderDatePick($("#changeAddress").val())
                        );
                        form.on("select(changeAddressFilter)", function (data) {
                          renderDatePick(data.value);
                        });
                        form.render("select");
                      }
                      $(".changeTimeAdd").show();
                    },
                  });
                }
                let outerSites = new Array();
                let outers = new Array();
                element.on("tab(onChangeAddress)", function (data) {
                  onChangeAddressIndex = data.index;
                  if (onChangeAddressIndex == 1) {
                    $.ajax({
                      url: base_url + "/meeting/externalSites/" + value,
                      async: false,
                      type: "GET",
                      headers: {
                        Accept: "application/json; charset=utf-8",
                        Authorization: layui.sessionData("userToken").key,
                      },
                      success: function (data) {
                        if (data.code == "200") {
                          var map = data.data;
                          result = map;
                          for (var k in map) {
                            outerSites.push({ name: k, value: map[k] });
                            outers.push(k);
                          }
                        } else {
                          layer.msg(data.message, { icon: 5 });
                        }
                      },
                    });
                    var attributionProjectSelect = xmSelect.render({
                      el: "#selectMeetingAddress",
                      filterable: true,
                      searchTips: "请输入会议地点",
                      radio: true,
                      clickClose: true,
                      remoteSearch: true,
                      remoteMethod: function (val, cb, show) {
                        if (val == "") {
                          return cb(outerSites);
                        }

                        $.ajax({
                          type: "GET",
                          async: false, //异步执行
                          url:
                            base_url + "/meeting/offlineOuterSites?key=" + val,
                          headers: {
                            Accept: "application/json; charset=utf-8",
                            Authorization: layui.sessionData("userToken").key,
                          },
                          success: function (data) {
                            if (data.code == 200) {
                              selectMeetingAddList = data.data;
                              var obj = [];
                              selectMeetingAddList.forEach(function (v, i) {
                                if ($.inArray(v.site, outers) == -1) {
                                  if (v.tip) {
                                    obj.push({
                                      name: v.site + " " + v.tip,
                                      value: v.site,
                                    });
                                  } else {
                                    obj.push({
                                      name: v.site,
                                      value: v.site,
                                    });
                                  }
                                }
                              });
                              if (obj.length > 0) {
                                cb(obj);
                              } else {
                                cb(outerSites);
                              }
                            }
                          },
                        });
                      },
                      on: function (data) {
                        var arr = data.arr;
                        if (arr.length > 0) {
                          if (Array.isArray(arr[0].value)) {
                            // result = arr;
                            meeetingAddress = arr[0].name;
                            renderDataW(arr[0].name);
                            $("#type").val(3);
                          } else {
                            meeetingAddress = arr[0].value;
                            renderDataW("");
                            $("#type").val(4);
                          }
                        }
                      },
                    });
                  }
                  // changeAdderess(onChangeAddressIndex);
                });
              },
              cancel: function (index, layero) {
                changeAdderess(onChangeAddressIndex);
                layer.close(index);
                return false;
              },
            });
          }
        },
      });
      var onChangeAddressIndex = " ",
        meeetingAddress = "";
      function changeAdderess(onChangeAddressIndex) {
        if (onChangeAddressIndex == 1) {
          var chooseAfterValueNew = indexItemm.sort((a, b) => {
            return a > b ? 1 : -1;
          });
          if (chooseAfterValueNew.length == 0) {
            $("#meetingTime").html(meeetingAddress);
          } else {
            $("#meetingTime").html(
              chooseAfterValueNew[0] +
                "-" +
                chooseAfterValueNew[1] +
                " " +
                meeetingAddress
            );
          }
          // $("#type").val(3);
        } else {
          var chooseAfterValueNew = indexItem.sort((a, b) => {
            return a > b ? 1 : -1;
          });
          if (chooseAfterValueNew.length == 0) {
            $("#meetingTime").html($("#changeAddress option:selected").val());
          } else {
            $("#meetingTime").html(
              chooseAfterValueNew[0] +
                "-" +
                chooseAfterValueNew[1] +
                " " +
                $("#changeAddress option:selected").val()
            );
          }
          $("#type").val(2);
        }
      }

      //周六周日不可选
      function disabled_date(value, appointmentDate) {
        var mm = value.year + "-" + value.month + "-" + value.date;
        $(".laydate-theme-grid table tbody")
          .find('[lay-ymd="' + mm + '"]')
          .removeClass("layui-this");
        if (appointmentDate != null && appointmentDate != "") {
          var dates = appointmentDate.split(",");
          for (var i = 0; i < dates.length; i++) {
            if (dates[i] == "7") {
              dates[i] = 0;
            }
            $("table>tbody>tr")
              .find("td:eq(" + dates[i] + ")")
              .addClass("laydate-disabled");
          }
        }
      }
    }
    function openEditLayer(arg) {
      var userMeetingId =
        arg.el.children[0].children[0].getAttribute("data-id");
      addIndex = layer.open({
        title: '<i class="fa fa-plus"></i>&nbsp;会议信息',
        type: 1,
        fix: false,
        skin: "layui-layer-rim",
        // 加上边框
        area: ["40%", "60%"],
        // 宽高
        content: $("#calendarForm").html(),
        success: function (layero, index) {
          initDateCtrl();
          $.ajax({
            url: base_url + "/meeting/" + arg.event.id,
            async: false,
            type: "GET",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            success: function (data) {
              var data = data.data,
                dataJson = {},
                startDate = data.startTime.split(" ")[0],
                startTime = data.startTime.split(" ")[1].substring(0, 5),
                endTime = data.endTime.split(" ")[1].substring(0, 5);
              dataJson.meetingTime =
                startDate + "   " + startTime + "-" + endTime;
              dataJson.title = data.meetingHeadline;
              dataJson.address = data.site;
              dataJson.meetingUserid = data.orgUserNumber;
              dataJson.meetingRemarks = data.remarks;
              dataJson.ackMsgs = data.ackMsgs;
              if (data.inviteLink == "") {
                $(".enterMeeting").hide();
              } else {
                $(".enterMeeting").attr(
                  "href",
                  "./launch.html?mid=" +
                    arg.event.id +
                    "&uid=" +
                    layui.sessionData("userName").key +
                    "&token=" +
                    layui.sessionData("userToken").key
                );
              }
              $(".meetingNotice").on("click", function () {
                window.location.href =
                  base_url + "/meeting/download/2/" + data.id;
              });
              form.val("calendarForm", dataJson);
            },
          });
          $.ajax({
            url: base_url + "/meeting/updMeetingStatus/" + userMeetingId,
            async: false,
            type: "GET",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            success: function (data) {
              if (data.type == "type") {
                calendar.render();
              }
            },
          });
        },
        cancel: function (index, layero) {
          calendar.refetchEvents();
          layer.closeAll("page");
        },
      });
    }
    $("#addSchedule").on("click", function (arg) {
      openMeetAddresSelect(arg);
    });
    function openMeetAddresSelect(arg) {
      meetAddresSelect = layer.open({
        title: '<i class="fa fa-plus"></i>&nbsp;会议选择',
        type: 1,
        fix: false,
        skin: "layui-layer-rim",
        area: ["40%", "45%"],
        content: $("#meetAddressSelect").html(),
        success: function (layero, index) {
          $(".onlineMeeting").on("click", function () {
            flagg = 1;
            type = 1;
            openLayer(arg, flagg);
            layer.close(index); //如果设定了yes回调，需进行手工关闭
          });
          $(".offlineMeeting").on("click", function () {
            flagg = 2;
            openLayer(arg, flagg);
          });
        },
      });
    }
    var projectNameText = "";
    function openLayer(arg, flagg) {
      addIndex = layer.open({
        title: '<i class="fa fa-plus"></i>&nbsp;新增会议',
        type: 1,
        fix: false,
        skin: "addMeetingFormSty",
        // 加上边框
        area: ["45%", "72%"],
        // 宽高
        content: $("#addMeetingForm").html(),
        success: function (layero, index) {
          initDateCtrl(flagg);
          var innerUsersDataNv = [];
          $.ajax({
            type: "GET",
            async: true, //异步执行
            url: base_url + "/user/selectUsers",
            headers: {
              Accept: "application/json; charset=utf-8",
              Authorization: layui.sessionData("userToken").key,
            },
            success: function (data) {
              var externalUsersData = data.data.externalUsers;
              externalUsersDataN = externalUsersData.map((item, index) => {
                return {
                  name: item.username,
                  value: index,
                };
              });
              participantsNSelect = xmSelect.render({
                el: "#participantsN",
                name: "pipelinesort",
                filterable: true,
                layVerify: "required",
                layVerType: "msg",
                theme: {
                  color: "#334d80",
                },
                language: "zn",
                data: externalUsersDataN,
              });
              var innerUsersData = data.data.innerUsers;
              innerUsersDataN = innerUsersData.map((item) => {
                return {
                  name: item.username,
                  value: item.userNumber,
                };
              });
              participantsWSelect = xmSelect.render({
                el: "#participantsW",
                name: "pipelinesort",
                filterable: true,
                layVerify: "required",
                layVerType: "msg",
                theme: {
                  color: "#334d80",
                },
                language: "zn",
                data: innerUsersDataN,
              });
            },
          });

          attributionProjectSelect = xmSelect.render({
            el: "#attributionProject",
            radio: true,
            name: "projectId",
            layVerify: "required",
            layVerType: "msg",
            theme: {
              color: "#334d80",
            },
            language: "zn",
            tips: "请选择归属项目",
            searchTips: "请选择归属项目",
            autoRow: true,
            clickClose: true,
            remoteSearch: true, //开启远程搜索
            filterable: true, //开启搜索
            create: function (val, arr) {
              if (arr.length === 0) {
                return {
                  name: val,
                  value: val,
                };
              }
            },
            remoteMethod: function (val, cb, show) {
              //这里如果val为空, 则不触发搜索
              if (!val) {
                return cb([]);
              }
              $.ajax({
                type: "GET",
                async: false, //异步执行
                url: base_url + "/projects/search?key=" + val,
                headers: {
                  Accept: "application/json; charset=utf-8",
                  Authorization: layui.sessionData("userToken").key,
                },
                success: function (data) {
                  if (data.code == 200) {
                    projectFlowlist = data.data;
                    //将循环后的数据取出name与value，把整个放到新数组里，最后放到cb()中
                    var obj = [];
                    projectFlowlist.forEach(function (v, i) {
                      if (v.hasOwnProperty("projectType")) {
                        obj.push({
                          name: v.projectName + "-" + v.projectType,
                          value: v.projectId,
                        });
                      } else if (v.tip) {
                        projectNameText = v.projectName;
                        obj.push({
                          name: v.projectName + "" + v.tip,
                          // name: `<span>${v.projectName}</span><span>${v.tip}</span>`,
                          value: v.projectId,
                        });
                      } else {
                        obj.push({
                          name: v.projectName,
                          value: v.projectId,
                        });
                      }
                    });
                    cb(obj);
                  } else {
                    layer.msg(res.msg, {
                      time: 2000,
                      icon: 5,
                    });
                  }
                },
              });
            },
          });

          $("#orgUserNumber").val(layui.sessionData("userName").key);
          // 表单提交事件
          form.on("submit(formSubmit)", function (d) {
            externalUsersDataO = participantsNSelect
              .getValue()
              .map((item, index) => {
                return {
                  userName: item.name,
                  userId: "",
                };
              });
            innerUsersDataO = participantsWSelect
              .getValue()
              .map((item, index) => {
                return {
                  userName: item.name,
                  userId: item.value,
                };
              });
            d.field.participantList =
              externalUsersDataO.concat(innerUsersDataO);

            d.field.startTime =
              $("#meetingDate").val() +
              " " +
              $("#meetingTime").html().split("-")[0] +
              ":" +
              "00";
            d.field.endTime =
              $("#meetingDate").val() +
              " " +
              $("#meetingTime").html().split("-")[1].split(" ")[0] +
              ":" +
              "00";
            if (d.field.projectId !== "") {
              d.field.projectId = attributionProjectSelect.getValue("valueStr");
              delete d.field.projectName;
            } else {
              delete d.field.projectId;
              d.field.projectName = projectNameText;
            }
            d.field.site = $("#meetingTime").html().split("-")[1].split(" ")[1];
            delete d.field.meetingDate;
            delete d.field.pipelinesort;
            // debugger;
            $.ajax({
              type: "POST",
              url: base_url + "/meeting",
              contentType: "application/json; charset=utf-8",
              async: true,
              data: JSON.stringify(d.field),
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              success: function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  window.isAddmeeting = true; // 修改会议状态
                  calendar.refetchEvents();
                  layer.msg(res.message, { icon: 1 });
                  $(".meetingNotice")
                    .removeClass("layui-btn-disabled")
                    .attr("disabled", false);
                  $(".enterMeeting")
                    .addClass("layui-btn-disabled")
                    .attr("disabled", true);
                  $(".meetingNotice").on("click", function () {
                    window.location.href =
                      base_url + "/meeting/download/2/" + res.data;
                    calendar.refetchEvents();
                    layer.closeAll("page");
                  });
                  return false;
                } else {
                  layer.msg(res.message, { icon: 2 });
                }
              },
            });

            return false;
          });
        },
        cancel: function (index, layero) {
          window.isAddmeeting = false;
          calendar.refetchEvents();
          layer.closeAll("page");
        },
      });
    }
  });
});
